<template>
	<view class="bg-white" style="height: 100%;">
		<cu-custom :bgColor="NavBarColor" :isBack="true" backFlag="navigate">
			<block slot="backText">返回</block>
			<block slot="content">位置信息</block>
		</cu-custom>
		<form>
			<view class="cu-form-group">
				<view class="title">经度</view>
				<input placeholder="请输入经度" name="input" v-model="annotation.longitude"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">纬度</view>
				<input placeholder="请输入纬度" name="input" v-model="annotation.dimension"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">地理位置</view>
				<textarea readonly placeholder="" name="input" v-model="annotation.address"></textarea>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg"  @click="onSubmit">提交</button>
			</view>
		</form>
	</view>
</template>

<script>


export default {
	data(){
		return{
			NavBarColor:this.NavBarColor,
			annotation:{
				id:"",
				deviceId:"",
				titile:"",
				startTime:"",
				sender:"",
				msgContent:"",
				recordVideo:"",
				userId:"",
				longitude:'',
				dimension:'',
				address:'',
			},
			goodNumber:null,
			flg:true,
			src:"",
			pic:"",
			userId:"",
		}
	},
	// onLoad:function(){
	// 	console.log("this.$Route.query",this.$Route);
	// 	let query = this.$Route.query
	// 	if(query){
	// 		this.annotation = query;
	// 		}
	// },
	onLoad: function (option) {
		this.annotation.deviceId=option.item
				
		let that = this
		uni.getLocation({
		  type: 'gcj02',
		  success: function (res) {
			that.annotation.longitude = res.longitude;
			that.annotation.dimension = res.latitude;
			var point = new plus.maps.Point(res.longitude, res.latitude);
			plus.maps.Map.reverseGeocode(
				point,
				{},
				function(event) {					
					var address = event.address; // 转换后的地理位置
					var point = event.coord; // 转换后的坐标信息
					var coordType = event.coordType; // 转换后的坐标系类型
					that.annotation.address=address;
					
				},
				function(e) {}
			);
		  }
		});
	},
	created(){
		console.log("created")
		//this.readOk();
	},
	methods:{
			onSubmit() {
				console.log('myform',this.annotation)
		
				this.$tip.loading();
				this.$http.put('/two/equipmentUpdate',this.annotation).then(res=>{
					console.log(res)
					this.$tip.loaded();
					if (res.data.success){
						this.$tip.toast('更新成功')
						let pages = getCurrentPages(); // 当前页面
						let beforePage = pages[pages.length - 2]; // 上一页
						uni.navigateBack({
						    success: function() {
						        beforePage.onLoad(); // 执行上一页的onLoad方法
						    }
						});
					}
				}).catch(()=>{
					this.$tip.loaded();
					this.$tip.error('提交失败')
				});
							
			},
		formatDate(text,len){
			if(!text || text.length==0){
				return ''
			}
			if(text.length<len){
				return text;
			}
			return text.substr(0,len)
		},
	}
}
</script>

<style>

</style>
